package com.ruoyi.blog.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.blog.domain.BlogLinkApply;
import com.ruoyi.blog.service.IBlogLinkApplyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 博客申请友链Controller
 * 
 * @author 谭潇
 * @date 2021-05-21
 */
@RestController
@RequestMapping("/blog/apply")
public class BlogLinkApplyController extends BaseController
{
    @Autowired
    private IBlogLinkApplyService blogLinkApplyService;

    /**
     * 查询博客申请友链列表
     */
    @PreAuthorize("@ss.hasPermi('blog:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlogLinkApply blogLinkApply)
    {
        startPage();
        List<BlogLinkApply> list = blogLinkApplyService.selectBlogLinkApplyList(blogLinkApply);
        return getDataTable(list);
    }

    /**
     * 导出博客申请友链列表
     */
    @PreAuthorize("@ss.hasPermi('blog:apply:export')")
    @Log(title = "博客申请友链", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BlogLinkApply blogLinkApply)
    {
        List<BlogLinkApply> list = blogLinkApplyService.selectBlogLinkApplyList(blogLinkApply);
        ExcelUtil<BlogLinkApply> util = new ExcelUtil<BlogLinkApply>(BlogLinkApply.class);
        return util.exportExcel(list, "博客申请友链数据");
    }

    /**
     * 获取博客申请友链详细信息
     */
    @PreAuthorize("@ss.hasPermi('blog:apply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(blogLinkApplyService.selectBlogLinkApplyById(id));
    }

    /**
     * 新增博客申请友链
     */
    @PreAuthorize("@ss.hasPermi('blog:apply:add')")
    @Log(title = "博客申请友链", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlogLinkApply blogLinkApply)
    {
        return toAjax(blogLinkApplyService.insertBlogLinkApply(blogLinkApply));
    }

    /**
     * 修改博客申请友链
     */
    @PreAuthorize("@ss.hasPermi('blog:apply:edit')")
    @Log(title = "博客申请友链", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlogLinkApply blogLinkApply)
    {
        return toAjax(blogLinkApplyService.updateBlogLinkApply(blogLinkApply));
    }

    /**
     * 删除博客申请友链
     */
    @PreAuthorize("@ss.hasPermi('blog:apply:remove')")
    @Log(title = "博客申请友链", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(blogLinkApplyService.deleteBlogLinkApplyByIds(ids));
    }
}
